<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "0" : request.getParameter("isShow");
	String type = request.getParameter("type") == null ? "" : request.getParameter("type");
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
	String id = request.getParameter("id") == null ? "" : request.getParameter("id");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建垫款单":"编辑垫款单" %></title>
			<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
	
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		  <script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
	<script type="text/javascript">
	var flag="<%=flag%>";
	jQuery(document).ready(function() {
		if(flag == '1'){
			jQuery('#lp').form({
				onLoadSuccess:function(){
					queueCompleteOver();
				}
			});
			
		}else{
				jQuery("#operation_date").datetimebox('setValue',getTodaySecond());
			var param="gd_id=<%=gd_id%>";
			jQuery.ajax({
					type:'GET',
					url:'<%=contextPath %>/springMVC/gd/getGDContentByGDId',
					dataType:"JSON",
					data:param,
					success:function(rtJson){
						jQuery("#fb_advances_id").val(rtJson.gd_worker_id);
						jQuery("#fb_advances").val(rtJson.gd_worker_name);
					}
				});
		}
		
		<%=isAdd?"":"jQuery('#lp').form('load','"+contextPath+"/springMVC/gd/getGdAdvancesById?id="+id+"');"%>
		          var settings = {
			      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
			      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
			      post_params: {
			    	 "module" : "<%=com.beaut.project.util.StaticData.GD_MODULE%>"
			      },
			      file_size_limit : "100 MB",
			      file_types : "*.*",
			      file_types_description : "All Files",
			      file_upload_limit : 100,
			      file_queue_limit : 0,
			      custom_settings : {
			        uploadArea : "fsUploadArea",
			        progressTarget : "fsUploadProgress",
			        startButtonId : "btnStart",
			        cancelButtonId : "btnCancel"
			      },
			      debug: false,
			      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
			      button_width: "65",
			      button_height: "29",
			      button_placeholder_id: "spanButtonUpload",
			      button_text: '<span class=\"textUpload\">上传附件</span>',
			      button_text_style: ".textUpload{color:#0000ff;}",
			      button_text_top_padding : 1,
			      button_text_left_padding : 18,
			      button_width: 80,
			      button_height: 20,
			      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			      button_cursor: SWFUpload.CURSOR.HAND,
			      
			      file_queued_handler : fileQueued,
			      file_queue_error_handler : fileQueueError,
			      file_dialog_complete_handler : fileDialogComplete,
			      upload_start_handler : uploadStart,
			      upload_progress_handler : uploadProgress,
			      upload_error_handler : uploadError,
			      upload_success_handler : uploadSuccessOver,
			      upload_complete_handler : uploadComplete,
			      queue_complete_handler : queueCompleteOver
			    };
			    swfupload = new SWFUpload(settings);
			  
			});
		
	 function uploadSuccessOver(file, serverData){
			  try {
			    var progress = new FileProgress(file, this.customSettings.progressTarget);
			    progress.toggleCancel(false);
			    var json = null;
			    json = serverData.evalJSON();
			    if(json.rtState=="1") {
			       progress.setError();
			       progress.setStatus("上传失败");
			    } else {
			       if($('attachmentId').value!=null && $('attachmentId').value!=""){
			    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
			       } 
			       else{
			    	   $('attachmentId').value = json.rtData.attachmentId;
			       }
			       if($('attachmentName').value!=null && $('attachmentName').value!=""){
			    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
			       } 
			       else{
			    	   $('attachmentName').value = json.rtData.attachmentName;
			       }
			    }
			  } catch (ex) {
			    this.debug(ex);
			  }
	}
	function queueCompleteOver(){
		var attachmentIds = $("attachmentId").value;
	    var attachmentNames = $("attachmentName").value;
	    if(attachmentIds){
	      jQuery('#attaTr').show();
       	  jQuery('#fsUploadArea').hide();
       	  if('<%=isShow%>' == 1){
	       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,true,'attach');
	     }else{
	       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
	     }
	    }
	 }
			 
	  function deleteAttachment(attachmentId,attachmentName){
		  var attrIds = $("attachmentId").value;
	    var attrNames = $("attachmentName").value;
	     var attrIdArrays = attrIds.split(",");
		  var attrNameArrays = attrNames.split("*");
		 var idArray = new Array();
		 var nameArray = new Array();
		 
		 for(var i=0;i<attrIdArrays.length;i++){
			 if(attrIdArrays[i] != attachmentId){
				 idArray.push(attrIdArrays[i]);
				 nameArray.push(attrNameArrays[i]);
			 }
		 }
		 $("attachmentId").value = idArray.join(",");
		 $("attachmentName").value = nameArray.join("*");
		 if($("attachmentId").value == ""){
			 jQuery('#attaTr').hide();
		 }
	  }
	  
	 
		function doSubmit(obj){
			jQuery("#lp").form('submit',{
					url:"<%=contextPath %>/springMVC/gd/<%=isAdd ? "addGdAdvances?gd_id="+gd_id : "updateGdAdvances?id=" + id+"&gd_id="+gd_id%>",	
					onSubmit:function(){
					var isValid = jQuery(this).form('validate');
					return isValid;
				},
				success:function(rtJson){
					rtJson = eval('(' + rtJson + ')'); 
					if (rtJson.rtState == '0'){
						eval('window.opener.<%=callback%>();');
						window.close();
					}else{
						warningInfo(rtJson.rtMsrg);
					}
				}
			});
		}
		
		function deleteRows(){
			var rows=jQuery('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				jQuery.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdAdvances",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								jQuery.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function deleteGDFinance(id){
			var rows=jQuery('#table').datagrid('getSelections');
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdAdvances",
						data:"ids="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/gd/viewAdvances.jsp?gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&advances_id="+id+"&isShow=2&objFlag=2";
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_ADVANCES_SHENPI%>")+"&businessId="+id;
	      jQuery(obj).hide();
	      jQuery.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							jQuery(obj).show();
						}
					});
	       
	    } 
		
		
	</script>
	</head>
	<body>
		<div id="ct" style="width: 97%;padding-left:10px" >
		<form id="lp" method="post">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td align="right" class="td1" nowrap>工单编号：</td>
					<td class="td2" nowrap>
						<input  id="gd_code" name="gd_code" readOnly value="<%=gd_code%>">
					</td>
					<td align="right" class="td1" nowrap>工单名称：</td>
					<td class="td2" nowrap>
						<input  id="gd_name" name="gd_name" readOnly value="<%=gd_name%>">
					</td>
				</tr>
					
				<tr>
				
						
					<td align="right" class="td1" nowrap>经办人部门：</td>
					<td class="td2" nowrap  >
						<input  id="dept_name" name="dept_name" readOnly value="<%=dept_name%>"/>
						<input type="hidden" id="dept_id" name="dept_id" readOnly value="<%=dept_id%>"/>
					</td>
					<td align="right" class="td1" nowrap>经办人：</td>
					<td class="td2" nowrap >
						<input type="hidden"  id="person_id" name="person_id"  value="<%=person_id%>"/>
						<input  id="person_name" name="person_name" readOnly value="<%=person%>"/>
					</td>
				
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>分包商：</td>
						<td class="td2" nowrap >
										<input type="hidden" id="fb_advances_id" name="fb_advances_id"  >
										<input type="text" id="fb_advances" readOnly name="fb_advances"   >
									</td>
					<td align="right" class="td1" nowrap >申请日期：</td>
					<td class="td2" nowrap  >
						<input  id="operation_date" name="operation_date" class="easyui-datetimebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>垫款标题：</td>
					<td class="td2" nowrap colspan='3' >
						<input  id="title" name="title" style="width:99%;"  class="easyui-validatebox"  data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>金额：</td>
					<td class="td2" nowrap >
							<input type="text" id="money" name="money" class="easyui-numberbox" data-options="required:true,min:0,precision:2"/>
					</td>
					<td align="right" class="td1" nowrap>利率：</td>
					<td class="td2" nowrap >
							<input type="text" id="rate" name="rate" class="easyui-numberbox" data-options="required:true,min:0,precision:2"/>&nbsp;&nbsp;&nbsp;<span style="color:red;">%</span>
					</td>
				</tr>
				
				<tr>
					<td align="right" class="td1" nowrap>摘要：</td>
					<td class="td2"  colspan='3'>
						<textarea id="remark" name="remark"  style="height:100%;width:99%" rows="6"></textarea>
					</td>
				</tr>
				</tr>
									<tr id="attaTr" style="display:none" >
								      <td nowrap align="right" class="td1">附件明细: </td>
								      <td class="td2"  colspan="3">
								        <input type="hidden" id="attachmentId" name="attachmentId">
								        <input type="hidden" id="attachmentName" name="attachmentName">
								        <span id="showAtt">
								        </span>
								      </td>
							   	    </tr>
								<tr>
							      <td nowrap align="right" class="td1">附件：</td>
							      <td class="td2" colspan="3">
							        	 <div id="fsUploadArea" class="flash" style="width:380px;">
										     <div id="fsUploadProgress"></div>
										     <div>
										       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
										       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
										    </div>
									      </div>
									      
										    <div id="attachment1">
									          <span id="spanButtonUpload" title="上传附件"></span>
									        </div>
							      </td>
					   		   </tr>
		 		    <%if(!"1".equals(isShow)){ %>
							<tr>
								<td align="right" class="td1" nowrap></td>
								<td class="td2" nowrap colspan='3'>
									<div align="left">
							  
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">提交</a>
								
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:parent.window.close();">关闭</a>
									</div>
								</td>
							</tr>
					<%} %>
			</table>
			</form>
		</div>
	
		
	</body>
</html>